﻿using SwenAssigment.Classes;
using SwenAssigment.DBClasses;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SwenAssigment
{
    public partial class StaffCreation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void SubmitBtn_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (Page.IsValid)
            {
                String Format = "M/d/yyyy";
                String DateStr = DobTbx.Text;
                DateTime ParsedDate = DateTime.ParseExact(DateStr, Format, CultureInfo.InvariantCulture);

                var Staff = new Staff() { StaffName = StaffNameTbx.Text, NRIC = NRICTbx.Text, BankAccountNumber = BankAccountTbx.Text, Address = AddressTbx.Text, ContactNumber = (Convert.ToInt32(ContactNumberTbx.Text)), Dob = ParsedDate, Job = JobTbx.Text };
                StaffDBManager.InsertStaff(Staff);

                Staff StaffTemp = StaffDBManager.GetStaffByNric(Staff.NRIC);
                if (DutyCBL.Items[0].Selected)
                {
                    StaffDBManager.InsertStaffGeneralDuty(StaffTemp.StaffId);
                }
                if (DutyCBL.Items[1].Selected)
                {
                    StaffDBManager.InsertStaffRoomDuty(StaffTemp.StaffId);
                }
                if (DutyCBL.Items[2].Selected)
                {
                    StaffDBManager.InsertStaffEstateDuty(StaffTemp.StaffId);
                }
                if (DutyCBL.Items[3].Selected)
                {
                    StaffDBManager.InsertStaffSecurityDuty(StaffTemp.StaffId);
                }
                Response.Redirect("~/StaffSuccessfulCreation.aspx");
            }
        }
    }
}